<?php
namespace Home\Controller;
use Think\Controller;
class GoodsController extends CommonController {

    //查看各支行情况
    public function index(){
    	$goodsTable = M('Goods');
    	//$goodsRes = $goodsTable->select();

    }
    

    //查看 所有 耗材信息
    //1 为查看所有上架， 0为所有耗材（包含已上架未上架）
    public function getGoods($status = '1'){
        $goodsTable = M('Goods');
        if ($status == '0') {
            $goodsRes = $goodsTable
                ->field('gid,rank,goodsname,price,amount,pic')
                ->select();
        }else{
            $where['status'] = '1';
            $goodsRes = $goodsTable->where($where)
                            ->field('gid,rank,goodsname,price,amount,pic')
                            ->select();
        }
        return $goodsRes;
    }

    //获取 根据商品gid 获取商品信息
    public function getRes($gid = 0){
    	
    	$goodsTable = M('Goods');
        $where['gid'] = $gid;
    	$goodsRes = $goodsTable->where($where)->find();
    	return $goodsRes;
    }

    //入库加库存 type=1、领用减库存type=2
    public function updateAmount($gid,$num,$type){

        $goodsTable = M('Goods');
        if ($type == '1') {
            $goodsTable->where('gid='.$gid)->setInc('amount',"$num");
           
        }else{
            $goodsTable->where('gid='.$gid)->setDec('amount',"$num");
        }
    }

}